using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Collections;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DALFaultDelivery
/// </summary>
[System.ComponentModel.DataObject]
public class DALFaultDelivery
{
    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public static List<FaultDelivery> GetFaultDeliveries()
    {
        return DAL.GetDataItems<FaultDelivery>(SQL.GetFaultDeliveries, new string[] { }, new object[] { });
    }

    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
    public static List<FaultDelivery> GetFaultDeliveriesByID(int deliverableID)
    {
        return DAL.GetDataItems<FaultDelivery>(SQL.GetFaultDeliveriesByID, new string[] { "@DeliverableID" }, new object[] { deliverableID });
    }

    public static int InsertFaultDelivery(int deliverableID, string faultDate, string reason, decimal refundAmount, bool isRepaid)
    {
        SqlCommand command = DAL.CreateCommand();
        command.CommandText = SQL.InsertFaultDelivery;
        command.CommandType = CommandType.Text;
        command.Parameters.AddWithValue("@DeliverableID", deliverableID);
        command.Parameters.AddWithValue("@FaultDate", faultDate);
        command.Parameters.AddWithValue("@Reason", reason);
        command.Parameters.AddWithValue("@RefundAmount", refundAmount);
        command.Parameters.AddWithValue("@IsRepaid", isRepaid);
        return DAL.ExecuteNonQuery(command);
    }

    public static int DeleteFaultDeliveries(ArrayList deliverablesIDs)
    {
        SqlCommand command = DAL.CreateCommand();
        command.CommandType = CommandType.Text;

        string s = "";
        foreach (string id in deliverablesIDs)
        {
            s += id + ",";
        }
        s = s.Substring(0, s.LastIndexOf(","));
        command.CommandText = SQL.DeleteFaultDeliveries + "(" + s + ")";

        return DAL.ExecuteNonQuery(command);
    }

    public static int UpdateFaultDelivery(int deliverableID, string faultDate, string reason, decimal refundAmount, bool isRepaid)
    {
        SqlCommand command = DAL.CreateCommand();
        command.CommandText = SQL.UpdateFaultDelivery;
        command.CommandType = CommandType.Text;
        command.Parameters.AddWithValue("@DeliverableID", deliverableID);
        command.Parameters.AddWithValue("@FaultDate", faultDate);
        command.Parameters.AddWithValue("@Reason", reason);
        command.Parameters.AddWithValue("@RefundAmount", refundAmount);
        command.Parameters.AddWithValue("@IsRepaid", isRepaid);
        return DAL.ExecuteNonQuery(command);
    }
}
